<?php


class MyMsServic
{
    private $serverName = '59.50.85.162';                  //服务器地址
    private $name = 'dahema';                       //登录账号
    private $password = 'tx*123456';                        //登录密码
    private $dbname = 'faxtongxiang';                 //数据库名称
    private $port='1433';                     //数据库端口
    private $CharacterSet = "UTF-8";
    private $connectionInfo='';



    public function __construct($serverName='',$name='',$password='',$dbname='',$CharacterSet='')
    {
        # code...
        if ($serverName!='') {
            # code...
            $this->serverName=$serverName;
        }
        if ($name!='') {
            # code...
            $this->name=$name;
        }
        if ($password!='') {
            # code...
            $this->pwd=$password;
        }
        if ($dbname!='') {
            # code...
            $this->dbname=$dbname;
        }
        if ($CharacterSet!=''){
            $this->CharacterSet=$CharacterSet;
        }

        $this->link();
//        echo "连接成功";

    }
    public function link(){
        $this->connectionInfo = array( "Database"=>$this->dbname, "UID"=>$this->name, "PWD"=>$this->password,'CharacterSet' => "UTF-8" );
        $this->conn = sqlsrv_connect( $this->serverName, $this->connectionInfo );
        if( $this->conn === false ) {
            echo "<pre>";
            var_dump(sqlsrv_errors());
            die( print_r( sqlsrv_errors(), true));
        }
//        return $this->conn;
    }
    public function exe_msdql($sql){
        $this->res=sqlsrv_query($this->conn,$sql);
        return $this->res;
    }

     function mGetMsAll($sql){
         $stmt=$this->exe_msdql($sql);

         if ($stmt===false){
             die(print_r(sqlsrv_errors(),true));
         }
//        $data=array();
         while($row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_NUMERIC))
         {
             $obj = (array)$row[4];
             echo "<pre>";
//             print_r($row);
             $this->data[]= array($row[0],$row[1],$row[2],$row[3],$obj['date'],$row[5]);

//   array($row[0],$row[1],$row[2],$row[3],$obj['date'],$row[5]))
             //echo $row[0].'*****'.$row[1].'*****'.$row[2].'*****'.$row[3].'*****'.$obj['date'].'*****'.$row[5]."<br>";
         }
         return $this->data;
    }







}